/*
 * Copyright (c) 2020 Carnegie Lee
 * All rights reserved
 */
package com.geekc.rabbitmq.producer.listener;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

/**
 * Confirm确认 - 消息是否正常发送至Broker
 * @author Carnegie Lee
 */
@Component
public class ConfirmCallback implements RabbitTemplate.ConfirmCallback {

    /**
     * 需要重写confirm方法
     * @param correlationData 消息的附加信息（包含唯一识别的ID）
     * @param ack 消息是否被Broker接收
     * @param cause 消息拒收的原因
     */
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        if (!ack)
            System.err.println("消息[id:" + correlationData.getId() + "]被拒收，原因是" + cause);
        //TODO
    }
}
